#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
#include <stdio.h>
#include <stdlib.h>

int main(int argc, char **argv)
{
    struct stat file_stat[argc];
    int ret;

    if(argc == 1){
        printf("The number of files entered was not what was expected!\n");
        exit(-1);
    }

    for(int i=1; i<argc; i++)
    {
        ret = stat(argv[i], &file_stat[i]);
        if(-1 == ret){
            perror("stat error");
            exit(-1);
        }

        printf("file name: %s\n", argv[i]);
        printf("file type: ");

        switch (file_stat[i].st_mode & S_IFMT){
            case S_IFSOCK:  printf("socket\n");            break;
            case S_IFLNK:   printf("symbolic link\n");      break;
            case S_IFREG:   printf("regular file\n");       break;
            case S_IFBLK:   printf("block device\n");       break;
            case S_IFDIR:   printf("directory\n");          break;
            case S_IFCHR:   printf("character device\n");   break;
            case S_IFIFO:   printf("FIFO\n");               break;
        }

        if (file_stat[i].st_mode & S_IROTH)
            printf("Read: Yes\n");
        else
            printf("Read: No\n");

        if (file_stat[i].st_mode & S_IWOTH)
            printf("Write: Yes\n");
        else
            printf("Write: No\n");

        printf("\n");
    }

    exit(0);
}